<template>
    <div class="main-container"  :class="wrap?'main-wrap-container':'main-no-wrap-container'" id="search-mixin-id">
    <main-content :title="contentTitle" >
        <div slot="search"  v-if="showSearchBox">
          <SearchBox 
            v-if="showSearchBox"
            :searchParamsList="searchParamsList" 
            :searchParam.sync="searchParam" 
            @searchBoxParams="searchClick" 
            @searchReset="searchReset" 
            ></SearchBox> 
        </div>
        <div slot="table">
        <!-- 在此处放置表格内容 -->
            <avue-crud ref="checkin_logTable" :data="listData" :showColumn="showColumn" :isSaveColumns="true" @selection-change="selectionChange" id="printTable" :option="option" stripe :page.sync="page"
                       @on-load="onPageLoad"
                       @row-dblclick="handleRowDBLClick"
					   :row-class-name="rowstyle"
                       @sort-change="sortChange" 
                       @current-row-change="handleCurrentRowChange" >
                <template slot-scope="scope" slot="menu">
                    <el-button type="opr-primary" size="mini"  icon="el-icon-view"  v-if="hasBtns('checkin_log:view')&&hasButtonPermission('checkin_log:view')" @click="viewForm(scope.row)">{{$t("crud.viewBtn")}}</el-button>
                    <el-button type="opr-primary" size="mini"  icon="el-icon-edit" v-if="hasBtns('checkin_log:modify')&&hasButtonPermission('checkin_log:modify')" @click="editForm(scope.row)":style="{ display: scope.row.is_checkout == '是'?'none':'' }">{{$t("crud.editBtn")}}</el-button>
                    <!-- <el-button type="opr-primary" size="mini"  icon="el-icon-delete" v-if="hasBtns('checkin_log:delete')&&hasButtonPermission('checkin_log:delete')" @click="deleteForm(scope.row)":style="{ display: scope.row.islocked==1?'none':'' }">{{$t("crud.delBtn")}}</el-button> -->
                    <!-- <el-button type="opr-primary" size="mini"  icon="el-icon-lock" v-if="hasBtns('checkin_log:lock')&&hasButtonPermission('checkin_log:lock')"  @click="confirm(scope.row)">{{$t(scope.row.islocked==1?'反确认':'确认')}}</el-button> -->
                </template> 
                 <template slot="menuLeft">
                     <!-- <el-button type="primary"  v-if="hasButtonPermission('checkin_log:add')" icon="el-icon-plus" size="small" @click="openForm()">{{$t("crud.addBtn")}}</el-button> -->
                     <!-- <el-button type="primary"  v-if="hasButtonPermission('checkin_log:batchDelete')" icon="el-icon-delete" size="small" @click="batchDelete()">{{$t("forme.editModal.batchDeletionBtn")}}</el-button> -->
                     
					 <el-button type="primary"  v-if="hasButtonPermission('checkin_log:print')" icon="el-icon-printer" size="small" @click="printForm">{{$t("editorModule.print")}}</el-button>
					 <el-button type="primary"  v-if="hasButtonPermission('checkin_log:export')" icon="fa fa-sign-out" size="small" @click="tableExport()">{{$t("forme.editModal.quickExportBtn")}}</el-button>
                </template>
            </avue-crud>
            <el-dialog title="入住登记"  v-dialogDrag :append-to-body="true" width="50%" :visible.sync="flag"  :class="isWorkflowForm ? 'work-form-dialog' : ''" :show-close="!isWorkflowForm" >
                <checkin_logForm v-if="flag"  :isEdit="isEdit" :disabled="disabled" @onChange="dialogChange" :keyValue="keyValue"></checkin_logForm> 
            </el-dialog>
        </div>
    </main-content>
    </div>
</template>
<script>
     import MainFixed from "@/page/main/MainFixed";
      import authorizeMixin from "@/mixins/authorize";
      import tableOptionMixin from "@/mixins/tableOption"; //table 高度计算
      import tableSearchMixin from "@/mixins/tableSearch"; //table 搜索 
      import displayColumnsMixin from "@/mixins/displayColumns"; //表格展示列显隐保存 
     import MainContent from "@/page/main/MainContent";
      import request from '@/router/axios';
      import { baseUrl } from '@/config/env';
      import { getOrder } from '@/util/util';
      import checkin_logForm from './checkin_logFormView';
     export default {
         name: "checkin_log",
         mixins: [authorizeMixin,tableOptionMixin,tableSearchMixin,displayColumnsMixin],
         components: { MainContent, checkin_logForm,MainFixed },
         data() {
              return {
				 	  btns:[
              'checkin_log:lock',
				 	     'checkin_log:refresh',
				 	     'checkin_log:add',
				 	     'checkin_log:view',
				 	     'checkin_log:modify',
				 	     'checkin_log:delete',
				 	     'checkin_log:batchDelete',
				 	     'checkin_log:print',
						 'checkin_log:export'
                   ],
                   page: {
                       pageSize: 20,
                       total: 0,
                       currentPage: 1,
                       layout: "total, prev, pager, next, jumper"
                   },
                   ids: '',
                   listData: [],
                   keyValue: '',
                   flag:false,
                   isEdit: true, // 查看-不显示按钮,
                   disabled: false, // 查看-禁用input,
                   isWorkflowForm:false,//默认值 false
                   defaultOrderfield:'',//默认排序字段
                   defaultOrder:'',//默认排序
                   searchParam: {}, 
                   defaultProps: {
                       children: 'children',
                       label: ''
                   },
                   option:{
                       rowKey:'fid',
                       highlightCurrentRow: true,
                       stripe: false,
                       addBtn: false,
                       tip:false,
                       menuWidth: 200,
                       border: true,
                       page: true,
                       selection: true,
                       index: true,
                       menu: false,
                       indexLabel: this.$t('custmerForm.tableNumber'),
                       align: 'center',
                       menuAlign: 'left',
                       delBtn: false,
                       editBtn: false,
                       column: [
                           {
                               sortable: true,
                               label: this.$t("姓名"),
                               prop: 'identify_name',
                               overHidden: true,
                           },
						   {
						       sortable: true,
						       label: this.$t("性别"),
						       prop: 'gender',
						       overHidden: true,
						   },
                           {
                               sortable: true,
                               label: this.$t("身份证号"),
                               prop: 'identify_id',
                               overHidden: true,
                           },
                           // {
                           //     sortable: true,
                           //     label: this.$t("事业部"),
                           //     prop: 'division',
                           //     overHidden: true,
                           // },
                           {
                               sortable: true,
                               label: this.$t("部门"),
                               prop: 'department',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("车间"),
                               prop: 'workshop',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("电话号码"),
                               prop: 'phone_number',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("入住日期"),
                               prop: 'checkin_date',
                               overHidden: true,
                           },
                           // {
                           //     sortable: true,
                           //     label: this.$t("夫妻房"),
                           //     prop: 'is_couple_room',
                           //     overHidden: true,
                           // },
                           {
                               sortable: true,
                               label: this.$t("房号"),
                               prop: 'room_number',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("是否 退宿"),
                               prop: 'is_checkout',
                               overHidden: true,
                           },
                           {
                               sortable: true,
                               label: this.$t("退宿日期"),
                               prop: 'checkout_date',
                               overHidden: true,
                           },
                       ]
                   }
              }
                   },
                   created() {
                       //是否有编辑 查看 删除 发起流程 发起临时流程权限 无则为操作列不显示
                       let oprBtns = ['checkin_log:lock','checkin_log:modify','checkin_log:view','checkin_log:delete','checkin_log:createFormFlow','checkin_log:createDesignFlow'];
                       let intersection = this.btns.filter((v) => oprBtns.includes(v)); 
                       if(intersection.length>0){
                       	this.option.menu =  true
                       }else{
                       	this.option.menu = false
                       }
                       let querySearchData = [
                       { 
                       		name: '房号', 
                       		DateField: '', 
                       		field: 'room_number', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '姓名', 
                       		DateField: '', 
                       		field: 'identify_name', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '身份证号', 
                       		DateField: '', 
                       		field: 'identify_id', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '事业部', 
                       		DateField: '', 
                       		field: 'division', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '部门', 
                       		DateField: '', 
                       		field: 'department', 
                       		tag: 'avue-load-tree', 
                       		avueType: 'load-tree', 
                       		lgmark: '', 
                       		__organize__: true, 
                       		__info__: false, 
                       		__type__: 'department', 
                       	}, 
                           { 
                       		name: '车间', 
                       		DateField: '', 
                       		field: 'workshop', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '电话号码', 
                       		DateField: '', 
                       		field: 'phone_number', 
                       		tag: 'el-input', 
                       		avueType: 'input-tip', 
                       		lgmark: '', 
                       	}, 
                       	{ 
                       		name: '入住日期', 
                       		DateField: '', 
                       		field: 'checkin_date', 
                       		tag: 'el-date-picker', 
                       		avueType: 'datetime', 
                       		lgmark: '', 
                       		"type": "date",
                       		"format": "yyyy-MM-dd",
                       		"value-format": "yyyy-MM-dd",
                       	}, 
                       	{ 
                       		name: '夫妻房', 
                       		DateField: '', 
                       		field: 'is_couple_room', 
                       		tag: 'el-radio-group', 
                       		avueType: 'radio', 
                       		lgmark: '', 
                       		dataType: 'dataItem', 
                       		dataItem: 'YesOrNo', 
                       	}, 
                       	{ 
                       		name: '是否 退宿', 
                       		DateField: '', 
                       		field: 'is_checkout', 
                       		tag: 'el-radio-group', 
                       		avueType: 'radio', 
                       		lgmark: '', 
                       		dataType: 'dataItem', 
                       		dataItem: 'YesOrNo', 
                       	}, 
                       	{ 
                       		name: '退宿日期', 
                       		DateField: '', 
                       		field: 'checkout_date', 
                       		tag: 'el-date-picker', 
                       		avueType: 'datetime', 
                       		lgmark: '', 
                       		"type": "date",
                       		"format": "yyyy-MM-dd",
                       		"value-format": "yyyy-MM-dd",
                       	}, 

                       ]
                       this.getSystemSearchList(querySearchData);
                       if(this.btns.length>0){
                       	let tempBtns =  this.btns.concat(oprBtns).filter((v) => this.btns.includes(v) && !oprBtns.includes(v));
                       	if(tempBtns.length>0){
                       		this.searchBtns  = [...new Set([...tempBtns])];
                       	}
                       }
                   },
                   methods: {
                         handleRowDBLClick (row, event) {
                         	if(this.hasBtns('checkin_log:modify')&&this.hasButtonPermission('checkin_log:modify')&&this.openDoubleClickEdit){
                         		this.editForm(row)
                         	}
                         },
						 rowstyle({row,menu}) {
						 	// console.log(row.isDeprecated)
						 	if(row.is_checkout == "是"){
						 		return "row-color1111";
						 	}
						 	
						 },
                         handleCurrentRowChange(row){
                         	this.$refs.checkin_logTable.toggleSelection([row]);
                         },
                         printForm() {
                         	let element = window.document.getElementById("printTable");
                         	setTimeout(() => {
                         	  html2canvas(element, {
                         		backgroundColor: null,
                         		useCORS: true,
                         		windowHeight: document.body.scrollHeight
                         	  }).then(canvas => {
                         		const url = canvas.toDataURL();
                         		this.printImg = url;
                         		printJS({
                         		  printable: url,
                         		  type: "image",
                         		  documentTitle: '打印',
                         		  scanStyles: false,
                         		  repeatTableHeader: false,
                         		  header: null
                         		});
                          	  });
                         	}, 1);
                           },
                         hasBtns(encode){
                         	return this.btns.includes(encode);
                         },
                         /* 获取公司用户数据 */
                         getListData() {
                         	if(!this.searchParam.order){
                         		this.searchParam.orderfield = this.defaultOrderfield;
                         		this.searchParam.order = this.defaultOrder;
                         	}
                            let params = this.changeSearchParams();
                            request({
                                url: baseUrl + '/checkin_log',
                                method: 'get',
                                params: params
                            }).then(res =>{
                                this.listData = res.data.data.Rows
                                this.page.total = res.data.data.Total;
								// for(let i = 0; i<res.data.data.Total;i++)
								// {
								// 	if(res.data.data.Rows[i].gender == 0)
								// 	{
								// 		this.listData[i].gender = "男"
								// 		// console.log(this.listData1[i].type)					
								// 	}
								// 	else{
								// 		this.listData[i].gender = "女"
								// 	}
								// }
								for(let i = 0; i<res.data.data.Total;i++)
								{
									if(res.data.data.Rows[i].is_checkout == 0)
									{
										this.listData[i].is_checkout = "否"
										// console.log(this.listData1[i].type)					
									}
									else{
										this.listData[i].is_checkout = "是"
									}
								}
                            })
                         },
                         /* 页面加载 */
                         onPageLoad(page) {
                            this.searchParam.limit = page.currentPage;
                            this.searchParam.size = page.pageSize;
                            this.getListData();
                         },
                          /*查看*/
                         viewForm(val) {
                           this.flag = true;
                           this.isEdit = false;
                           this.disabled = true;
                           this.keyValue = val.fid;
                         },
                          /* 编辑 */
                         editForm(val) {
                           this.flag = true; 
                           this.isEdit = true;
                           this.disabled = false;
                           this.keyValue = val.fid;
                         },
                          /* 打开表单 */
                         openForm(){
							  if(!this.isWorkflowForm){
                             //不处理工作流表单时候，表单类型重置
                             window.localStorage.setItem('systemFormType',0);
                           }
                           this.disabled = true;
                           this.keyValue = null; 
                           this.flag = true; 
                           this.isEdit = false; 
                         },
                         /* 确认*/
                         confirm(val) {
                            this.$confirm(this.$t("是否确认"), this.$t("tip"), {
                              confirmButtonText: this.$t("buttonModule.modalSureBtn"),
                              cancelButtonText: this.$t("editorModule.cancel"),
                              type: "warning",
                             }).then(() => {
                                 request({
                                     url: baseUrl + "/checkin_log/confirm/" + val.fid,
                                     method: "post",
                                 }).then((res) => {
                                     this.getListData()
                                     this.$notify({
                                      title: this.$t("Notice.hintSuccess"),
                                      message: this.$t("确认成功"),
                                      type: "success",
                                     }).catch((e) => {});
                                 });
                             });
                         },
                          /* 删除 */
                         deleteForm(val) {
                            this.$confirm(this.$t("deletePrompt.promptContent"), this.$t("tip"), {
                              confirmButtonText: this.$t("buttonModule.modalSureBtn"),
                              cancelButtonText: this.$t("editorModule.cancel"),
                              type: "warning",
                             }).then(() => {
                                 request({
                                     url: baseUrl + "/checkin_log/" + val.fid,
                                     method: "delete",
                                 }).then((res) => {
                                     this.getListData()
                                     this.$notify({
                                      title: this.$t("Notice.hintSuccess"),
                                      message: this.$t("deletePrompt.successDeleted"),
                                      type: "success",
                                     });
                                 });
                             });
                         },
                          /* 分页 */
                         sortChange(data) {
                         	if(data.order){
                         		let order= getOrder(data.order);
                         		this.searchParam.order = order;
                         		this.searchParam.orderfield = data.prop;
                         	}else{
                         		this.searchParam.order = this.defaultOrder;
                         		this.searchParam.orderfield = this.defaultOrderfield;
                         	}
                         	this.getListData()
                         },
                          /* 弹窗回调 */
                          dialogChange(b){
                              this.flag = false;
                              this.$nextTick(()=>{
                              this.getListData();
                         })},
						 /* 导出 */
						  tableExport(){
						    this.$refs["checkin_logTable"].rowExcel()
						    return;
						 },
                          /* 查询 */
                           searchClick(params) {
                            this.page.currentPage=1;
                            this.searchParam.limit = 1;
                            this.searchParam.size = this.page.pageSize;
                            this.searchParam = params;
                            this.getListData()
                         },
                           /* 查询表单重置 */
                           searchReset() {
                            for (const key in this.searchParam) {
                                 if(this.searchParam[key]){
                                     this.searchParam[key] = null;
                                 }
                            }
                            this.page.currentPage=1;
                            this.searchParam.limit = 1;
                            this.searchParam.size = this.page.pageSize;
                            this.getListData();
                         },
                           selectionChange(list){
                             this.ids = list.map((x) => x.fid).join(',');
                           },
                           batchDelete() {
                            if (!this.ids || this.ids.split(",").length === 0) {
                                 this.$message.error(this.$t("deletePrompt.noSelected"));
                                 return;
                           }
                             this.$confirm(this.$t("deletePrompt.promptContent"), this.$t("tip"), {
                               confirmButtonText: this.$t("buttonModule.modalSureBtn"),
                               cancelButtonText: this.$t("editorModule.cancel"),
                               type: "warning",
                             }).then(() => {
                               request({
                                 url: baseUrl + "/checkin_log/" + this.ids,
                                 method: "delete",
                               }).then((res) => {
                                 this.getListData();
                                 this.$notify({
                                   title: this.$t("Notice.hintSuccess"),
                                   message: this.$t("deletePrompt.successDeleted"),
                                   type: "success",
                                 });
                               });
                             });
                           },
         }
     }
</script>
<style>
	.row-color1111 {
		background-color:#ffff00;
		
	}
.searchBox {
   width: calc(100% - 218px);
   display: inline-block;
}
.main-container{
   height: 100%!important;
   padding: 0 8px!important;
}
div /deep/ .custom-tree-node span{
   font-size: 14px;
   padding-left: 10px;
}
div /deep/ .custom-tree-node i{
   font-size: 12px;
}
div /deep/ .el-dialog__body{
height: 70vh;
overflow: scroll;
}
</style>
